﻿using AutoMapper;
using B.S.Warehouse.Domain.goods;
using B.S.Warehouse.ErrorCord;
using B.S.Warehouse.Read.Api.Application.Command.GoodsCommand;
using MediatR;
using SqlSugar;

namespace B.S.Warehouse.Read.Api.Application.Handelr.GoodsHandler
{
    public class FTGoodsHandler : IRequestHandler<FTGoodsCommand, ApiResult<List<GoodsModel>>>
    {
        private readonly IMapper mapper;
        private readonly ISqlSugarClient db;

        public FTGoodsHandler(IMapper mapper, ISqlSugarClient db)
        {
            this.mapper = mapper;
            this.db = db;
        }
        public async Task<ApiResult<List<GoodsModel>>> Handle(FTGoodsCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<GoodsModel>> result = new ApiResult<List<GoodsModel>>();
            result.Code = ApiEnum.显示成功;
            result.MAG = ApiEnum.显示成功.ToString();
            var list = await db.Queryable<GoodsModel>().Where(x => x.IsDel == false && x.GoodsModelId == request.GoodsModelId).ToListAsync();
            result.data = list;
            return await Task.FromResult(result);
        }
    }
}
